package com.jmp.security.grant;

import com.jmp.security.base.ClientDetail;
import com.jmp.security.base.RequestDetail;
import com.jmp.security.base.UserDetail;
import one.stand.advice.ResultEnum;
import one.stand.enums.CompanyStateEnums;
import one.stand.mapper.CompanyMapperExt;
import one.stand.service.BusinessCardBaseService;
import one.stand.util.AssertUtil;

public class CardUserDetailValidServiceImpl<T extends RequestDetail> extends UserDetailValidServiceImpl<T> {
    public CardUserDetailValidServiceImpl(BusinessCardBaseService businessCardBaseService, CompanyMapperExt companyMapperExt) {
        super(businessCardBaseService, companyMapperExt);
    }

    @Override
    public void check(T requestDetail, ClientDetail clientDetail, UserDetail userDetail) {
        super.check(requestDetail, clientDetail, userDetail);

        AssertUtil.nonNull(userDetail.getCardModel(), ResultEnum.PARAM_CHECK, "您未创建名片，没有权限登录");
        AssertUtil.isTrue(userDetail.getCardModel().getIsDel() == 0, ResultEnum.PARAM_CHECK, "名片不存在");

        AssertUtil.nonNull(userDetail.getCompany(), ResultEnum.PARAM_CHECK, "企业不存在");
        AssertUtil.isTrue(userDetail.getCompany().getIsDel() == 0, ResultEnum.PARAM_CHECK, "企业不存在");
        AssertUtil.isTrue(CompanyStateEnums.NORMAL.getState().equals(userDetail.getCompany().getCompanyState()),
                ResultEnum.PARAM_CHECK,
                "企业已禁用，请联系客服");
    }
}
